<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: rgb(234, 237, 240);
        }

        .t1 {
            text-align: center;
            font-size: 30px;
            font-weight: bold;
            line-height: 150px;
        }

        .box {
            height: 450px;
            border: 1px solid rgb(255, 255, 255);
            border-radius: 15px;
            margin: 50px;
            background-color: rgb(255, 255, 255);
        }

        .box .title {
            font-weight: bold;
            line-height: 60px;
            text-align: center;
        }

        .box .block {
            margin: 30px 0;
        }

        .box .block input {
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 75%;
            outline: none;
            box-sizing: border-box;
            display: block;
            margin-left: auto;
            margin-right: auto;

        }

        .block-l input {
            height: 60px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 75%;
            outline: none;
            box-sizing: border-box;
            background-color: rgb(107, 107, 243);
            color: aliceblue;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
</head>

<body>
    <div class="t1">阿里云盘</div>
    <div class="box">
        <div class="title">注册新账号</div>
        <div class="block">
            <input type="text" placeholder="请输入账号">
        </div>
        <div class="block">
            <input type="password" placeholder="请输入密码">
        </div>
        <div class="block">
            <input type="password" placeholder="确认密码">
        </div>
        <div class="block-l">
            <input type="button" value="注册">
        </div>
    </div>

    <script src="./封装函数.js"></script>

    <script>
        //获取五个input输入框
        var inpts = document.querySelectorAll('.box .block input');
        var inpt = document.querySelector('.box .block-l input')

        //给button绑定点击事件
        inpt.onclick = function () {
            //对表单内容做校验( 为空校验, 格式校验 )
            if (inpts[0].value && inpts[1].value === inpts[2].value) {
                //if( /^1[3-9]\d{9}$/.test( inpts[0].value ) && /^\d{4}$/.test(inpts[1].value) ){
                if (/^\d{4}$/.test(inpts[1].value)) {
                    //通过校验, 发起登陆请求
                    ajax('get', 'https://yantianfeng.com/api/register', {
                        username: inpts[0].value,
                        password: inpts[1].value,
                    }, function (data) {
                        // console.log(data);
                    })
                } 
                else {
                    alert('请输入正确的手机号/密码')
                }
            } else {
                alert('用户名/密码不能为空!')
            }

        }

    </script>

</body>

</html>